<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="util" uri="/WEB-INF/kdd-util.tld" %>
<%@taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<sec:authorize access="isAuthenticated()">
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        </head>
        <body>
            <jsp:include page="menu.jsp" />
            <script type="text/javascript">
                $(function() { 
                    var t = $('table#datatable')
                    $("#datafilter").keyup(function() {
                        $.uiTableFilter( t, this.value );
                    })
                });
                $(function() { 
                    var t = $('table#listtable')
                    $("#filter").keyup(function() {
                        $.uiTableFilter( t, this.value );
                    })
                });
            </script>
            <div class="notfullnomargin">
                <h3><spring:message code="msg.hello" />, ${user.username}<br /></h3><br />
                <div class="columnholder row">
                    <div class="well columnleft">
                        <b><spring:message code="msg.leadprojects" />:</b><br /><br />
                        <c:choose>
                            <c:when test="${empty leadProjects}">
                                <spring:message code="msg.noleadprojects" />
                            </c:when>
                            <c:otherwise>
                                <input type="text" id="projectfilter" placeholder="Filter" />
                                <ul id="projectlist">
                                    <c:forEach items="${leadProjects}" var="sp">
                                        <li><span><a href="<c:url value='/project/${sp.id}'/>">${sp.name}</a></span></li>
                                    </c:forEach>
                                </ul>
                            </c:otherwise>
                        </c:choose>
                    </div>
                    <div class="well columnright">
                        <b><spring:message code="msg.researchersubs" />:</b><br /><br />
                        <c:choose>
                            <c:when test="${empty researcherProjects}">
                                <spring:message code="msg.noresearchersubs" />
                            </c:when>
                            <c:otherwise>
                                <input type="text" id="subprojectfilter" placeholder="Filter" />
                                <ul id="subprojectlist">
                                    <c:forEach items="${researcherProjects}" var="sp">
                                        <li><span><a href="<c:url value='/subproject/${sp.id}'/>">${sp.name}</a></span></li>
                                    </c:forEach>
                                </ul>
                            </c:otherwise>
                        </c:choose>
                    </div>
                </div>
                <c:if test="${not empty lastResults}">
                    <div class="well">
                        <h4><spring:message code="msg.results" /></h4><br />
                        <div>
                            <input type="text" id="filter" placeholder="Filter" />
                            <table id="listtable" class="table table-striped table-bordered table-condensed">
                                <thead>
                                    <tr>
                                        <th class="creationdate"><spring:message code="msg.creationdate" /></th>
                                        <th><spring:message code="msg.method" /></th>
                                        <th><spring:message code="msg.creator" /></th>
                                        <th class="details"><spring:message code="msg.details" /></th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <c:forEach items="${lastResults}" var="r">
                                        <tr>
                                            <td><fmt:formatDate value="${r.creationDate}" pattern="MM/dd/yyyy HH:mm"/></td>
                                            <td>${r.method.showName}</td>
                                            <td>${r.creator.username}</td>
                                            <td><a href="<c:url value='/result/${r.id}'/>"><spring:message code="msg.details" /></a></td>
                                        </tr>
                                    </c:forEach>
                                </tbody>
                            </table>
                            <strong><a href="<c:url value='/allresults'/>"><spring:message code="msg.showallresults" /></a></strong>
                        </div>
                    </div>
                </c:if>
                <c:choose>
                    <c:when test="${empty leadProjects}">
                    </c:when>
                    <c:otherwise>
                        <div class="well">
                            <h2><spring:message code="msg.subprojectsleadprojects" /></h2><br />
                            <c:forEach items="${leadProjects}" var="lp">
                                <div class="well">
                                    <h4>${lp.name}</h4><br />
                                    <table class="table table-striped table-bordered table-condensed ">
                                        <thead>
                                            <tr>
                                                <th class="creationdate"><spring:message code="msg.name" /></th>
                                                <th class="creationdate"><spring:message code="msg.created" /></th>
                                                <th class="details"><spring:message code="msg.details" /></th>
                                                <th class="edit"><spring:message code="msg.edit" /></th>
                                                <th class="delete"><spring:message code="msg.delete" /></th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            <c:forEach items="${lp.subProjects}" var="sp">
                                                <tr>
                                                    <td>${sp.name}</td>
                                                    <td><fmt:formatDate value="${sp.creationDate}" pattern="MM/dd/yyyy HH:mm"/></td>
                                                    <td><a class="btn btn-mini btn-info" href="<c:url value='/subproject/${sp.id}' />"><spring:message code="msg.details" /></a></td>
                                                    <td><a id="editLink" class="btn btn-mini btn-info" href="<c:url value='/researcher/subproject/edit/${sp.id}' />"><spring:message code="msg.edit" /></a></td>
                                                    <td><a id="deleteLink" class="btn btn-mini btn-danger" href="<c:url value='/researcher/subproject/delete/${sp.id}' />"><spring:message code="msg.delete" /></a></td>
                                                </tr>
                                            </c:forEach>
                                        </tbody>
                                    </table>
                                    <a href="<c:url value='/researcher/subproject/add' />" class="btn btn-mini btn-primary"><spring:message code="msg.addsubproject" /></a><br /><br/>
                                </div>
                            </c:forEach>
                        </div>
                    </c:otherwise>
                </c:choose>
                <div class="well">
                    <h2><spring:message code="msg.uploadeddata" /></h2>
                    <input type="text" id="datafilter" placeholder="Filter" />
                    <table id="datatable" class="table table-striped table-bordered table-condensed ">
                        <thead>
                            <tr>
                                <th><spring:message code="msg.name" /></th>
                                <th class="creationdate"><spring:message code="msg.created" /></th>
                                <th class="details"><spring:message code="msg.type" /></th>
                                <th class="details"><spring:message code="msg.details" /></th>
                                <th class="delete"><spring:message code="msg.delete" /></th>
                            </tr>
                        </thead>
                        <tbody>
                            <c:forEach items="${uploadedData}" var="data">
                                <c:if test="${util:isInstanceOf(data, 'at.tugraz.hidipic.model.InputDataItem')}">
                                    <tr>
                                        <td>${data.title}</td>
                                        <td><fmt:formatDate value="${data.created}" pattern="MM/dd/yyyy HH:mm"/></td>
                                        <td>${data.type}</td>
                                        <td><a class="btn btn-mini btn-info" target="_blank" href="<c:url value='${data.url}' />"><spring:message code="msg.details" /></a></td>
                                        <td><a id="deleteLink" class="btn btn-mini btn-danger" href="<c:url value='/researcher/data/delete/${data.name}' />"><spring:message code="msg.delete" /></a></td>
                                    </tr>
                                </c:if>
                            </c:forEach>
                        </tbody>
                    </table>
                </div>
            </div>
            <script type="text/javascript">
                $("#subprojectfilter").keyup( function() {
                    filterList($("#subprojectlist"), $(this).val());
                });
                $("#projectfilter").keyup( function() {
                    filterList($("#projectlist"), $(this).val());
                });
            </script>
            <jsp:include page="foot.jsp" />
        </sec:authorize>